﻿using Microsoft.EntityFrameworkCore;
using MiniErp.Entity.DataStreams;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MiniErp.Repository.BaseRepository
{
    /// <summary>
    /// 总仓储接口(通用增删改查)
    /// </summary>
    public interface IBaseRepository<TEntity>
        where TEntity : BaseEntity
    {
        /// <summary>
        /// 新增一条信息
        /// </summary>
        /// <param name="t">新增的实体对象</param>
        void AddInfoAsync(TEntity t);
        /// <summary>
        /// 新增多条信息
        /// </summary>
        /// <param name="t">新增的实体对象集合</param>
        void AddInfoAsync(List<TEntity> t);
        /// <summary>
        /// 删除一条信息
        /// </summary>
        /// <param name="t">删除的实体对象</param>
        void DeleteInfoAsync(TEntity t);
        /// 删除多条信息
        /// </summary>
        /// <param name="t">删除的实体对象集合</param>
        void DeleteInfoAsync(List<TEntity> t);
        /// <summary>
        /// 修改一条信息
        /// </summary>
        /// <param name="t">修改后的实体对象</param>
        void UpdateInfoAsync(TEntity t);
        /// <summary>
        /// 修改多条信息
        /// </summary>
        /// <param name="t">修改后的实体对象集合</param>
        void UpdateInfoAsync(List<TEntity> t);
        /// <summary>
        /// 查询一条信息
        /// </summary>
        /// <param name="lambda">查询条件 SingleOrDefaultAsync(lambda)</param>
        /// <returns>指定查询条件的数据（超过一条会异常）</returns>
        Task<TEntity> GetInfoAsync(Expression<Func<TEntity, bool>> lambda);
        /// <summary>
        /// 查询多条信息
        /// </summary>
        /// <param name="lambda">查询条件 where(lambda)</param>
        /// <returns>指定查询条件的数据</returns>
        Task<List<TEntity>> GetInfoAsyncs(Expression<Func<TEntity, bool>> lambda);
        /// <summary>
        /// 查询所有信息
        /// </summary>
        /// <returns>指定表的所有信息</returns>
        Task<List<TEntity>> GetInfoAsyncs();

        /// <summary>
        ///  查询多条信息//分页
        /// </summary>
        /// <typeparam name="Ttype">排序条件的类型</typeparam>
        /// <param name="lambda">查询条件where(lambda)</param>
        /// <param name="Page">页码</param>
        /// <param name="num">每页数据条数</param>
        /// <param name="value">排序条件(会自动从字符串转 Ttype 类型)</param>
        /// <param name="isAsc">ture正序排序，false逆序</param>
        /// <returns>指定查询条件的数据//分页</returns>
        Task<List<TEntity>> GetInfoAsyncs<Ttype>(Expression<Func<TEntity, bool>> lambda, int Page, int num, string value, bool isAsc = true);
        /// <summary>
        /// 查询所有信息//分页
        /// </summary>
        /// <typeparam name="Ttype">排序条件的类型</typeparam>
        /// <param name="Page">页码</param>
        /// <param name="num">每页数据条数</param>
        /// <param name="value">排序条件(会自动从字符串转 Ttype 类型)</param>
        /// <param name="isAsc">ture正序排序，false逆序</param>
        /// <returns>指定表的所有信息//分页</returns>
        Task<List<TEntity>> GetInfoAsyncs<Ttype>(int Page, int num, string value, bool isAsc = true);

        /// <summary>
        /// 查询指定条件的数据条数
        /// </summary>
        /// <param name="lambda">查询条件Count(lambda)</param>
        /// <returns>指定条件的数据条数</returns>
        Task<int> GetInfoNumsAsync(Expression<Func<TEntity, bool>> lambda);


    }
}
